
(function () {
    
    function configure() {

    }

    configure.prototype={
        //注册验证
        theNextRegister:function () { //注册跳回
            var callback=["mall1.poc.pub","mall2.poc.pub","mall.96225.com"];
            var no_callback=["mall.96225.com/jdvop"]
            var callback_url=window.localStorage.getItem("callback_url");
            // url 解码
            var callback_url_new=decodeURIComponent(callback_url);
            var hostAll=callback_url_new.split("/");
            var _length=no_callback.filter(function (e) {
                return callback_url_new.indexOf(e) > -1
            }).length;
            if(_length==0){
                if(callback_url_new){
                    for(var i=0;i<callback.length;i++){
                        if(callback_url_new.indexOf(callback[i])>-1){
                            var backHref=hostAll[0]+"//"+hostAll[2]+"/mobile/#/register?callback_url="+callback_url;
                            // console.log(backHref)
                            window.location.href=backHref;
                        }
                    }
                }
            }
        },
	getUrlParam:function (name) { //获得url参数
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return r[2]; return null;
        },

        //数据ajax获取
        connect:function (url,type,params,fun) {
            $.ajax({
                url:url,
                type:type, //GET
                async:true,    //或false,是否异步
                data:params,
                timeout:5000,    //超时时间
                dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                beforeSend:function(xhr){
                    console.log('发送')
                },
                success:function(data,textStatus,jqXHR){
                    fun(data,textStatus);

                },
                error:function(xhr,textStatus){
                        var txtErr;
                        if(!window.navigator.onLine){
                            txtErr="无网络"
                        }else{
                            txtErr="服务器错误"
                        }
                        fun({},textStatus,txtErr);
                },
                complete:function(){

                }
            })

        },

        //app登录严重
        smkapp:function () {
            var userAgent= window.navigator.userAgent;
            var isAndroid = userAgent.indexOf('Android') > -1 || userAgent.indexOf('Adr') > -1; //android终端
            var isiOS = !!userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
            if(isAndroid||isiOS){

            }
        },
        //cookie
        cookieConfig:function (wap_token,user_id) {
            var callback_url = window.localStorage.getItem("callback_url");
            var callback_url_new=decodeURIComponent(callback_url);
            var strRegex ='(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]';
            var re=new RegExp(strRegex);
            if(callback_url_new!="")
            {
                // if (!re.test(callback_url)) {
                //     alert("请输入正确的url地址");
                // }else{
                    var host=callback_url_new.split("/")[2];
                    var hostItem= host.split(".");
                    var hostCount= hostItem.length;
                    var url_path=hostItem[hostCount-2]+"."+hostItem[hostCount-1];
                    // alert(url_path)
                    if(url_path.indexOf(":")>-1){
                        url_path=url_path.substring(0,url_path.indexOf(":"))
                    }
                    $.cookie('mobile', null,{ path: '/'});
		    $.cookie('mobile', null,{ path: '/',domain:url_path});
                    //$.cookie('o2osign', null,{ path: '/'});
                    //$.cookie('o2osign', null,{ path: '/',domain:url_path});
                    $.cookie('wap_token', wap_token,{ path: '/',domain:url_path,expires:7});
                    //$.cookie('o2osign', wap_token,{ path: '/',domain:url_path,expires:7});
			$.cookie('mobile', user_id,{ path: '/',domain:url_path,expires:7});
                    window.location.replace(callback_url_new);
                // }

            }else{
                alert("callback_url不能为空");
            }



        },

        url_smk:document.location.protocol+"//o2o.96225.com/" //正式
        // url_smk:document.location.protocol+"//115.236.162.164:2280/",//测试

    }
    window.configure=configure;

    jQuery.cookie = function(name, value, options) {
        if (typeof value != 'undefined') { // name and value given, set cookie
            options = options || {};
            if (value === null) {
                value = '';
                options.expires = -1;
            }
            var expires = '';
            if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
                var date;
                if (typeof options.expires == 'number') {
                    date = new Date();
                    date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
                } else {
                    date = options.expires;
                }
                expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
            }
            // CAUTION: Needed to parenthesize options.path and options.domain
            // in the following expressions, otherwise they evaluate to undefined
            // in the packed version for some reason...
            var path = options.path ? '; path=' + (options.path) : '';
            var domain = options.domain ? '; domain=' + (options.domain) : '';
            var secure = options.secure ? '; secure' : '';
            document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
        } else { // only name given, get cookie
            var cookieValue = null;
            if (document.cookie && document.cookie != '') {
                var cookies = document.cookie.split(';');
                for (var i = 0; i < cookies.length; i++) {
                    var cookie = jQuery.trim(cookies[i]);
                    // Does this cookie string begin with the name we want?
                    if (cookie.substring(0, name.length + 1) == (name + '=')) {
                        cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                        break;
                    }
                }
            }
            return cookieValue;
        }
    };

})()

